package com.richapp.launcher.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.util.Log;

import com.richapp.launcher.common.AdvType;
import com.richapp.launcher.dao.adv.Adv;
import com.richapp.launcher.service.AdvService;
import com.richapp.launcher.ui.activities.StartActivity;
import com.richapp.launcher.utils.ServiceUtil;
import com.richapp.launcher.utils.Tools;
import com.tencent.bugly.beta.Beta;

import java.util.ArrayList;
import java.util.List;

public class BootBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

/*        //启动应用
        Intent app = context.getPackageManager().getLaunchIntentForPackage("com.richapp.launcher");
        context.startActivity(app);*/
        //导入数据
        Tools.importDatabaseRawFile(context);
//        DbUtil.setupDB(context);
        //initAdvMap();
        //启动服务
        ServiceUtil.startService(context);
//        Beta.checkUpgrade();
        
    }

    public void initAdvMap() {
        List<Adv> boots = AdvService.advMap.get(AdvType.BOOT_TYPE);
        List<Adv> screenons = AdvService.advMap.get(AdvType.SCREEN_ON_TYPE);
        List<Adv> screensavers = AdvService.advMap.get(AdvType.SCREEN_SAVER_TYPE);

        if (boots == null) {
            boots = new ArrayList<Adv>();
            AdvService.advMap.put(AdvType.BOOT_TYPE, boots);
        }

        if (screenons == null) {
            screenons = new ArrayList<Adv>();
            AdvService.advMap.put(AdvType.SCREEN_ON_TYPE, screenons);
        }
        if (screensavers == null) {
            screensavers = new ArrayList<Adv>();
            AdvService.advMap.put(AdvType.SCREEN_SAVER_TYPE, screensavers);
        }

//        List<Adv> advs = DbUtil.daoSession.getAdvDao().listAdvs();
//        for (Adv adv : advs) {
//            if (adv.getType() == AdvType.BOOT_TYPE) {
//                boots.add(adv);
//            } else if (adv.getType() == AdvType.SCREEN_ON_TYPE) {
//                screenons.add(adv);
//            } else if (adv.getType() == AdvType.SCREEN_SAVER_TYPE) {
//                screensavers.add(adv);
//            }
//        }

    }




}
